package com.neusoft.bizcore.auth.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotBlank;

import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractModel;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
public class AuthOganization extends AbstractModel {

    private static final long serialVersionUID = 1L;

    /** 组织名 */
    @NotBlank(message = "组织名不能为空")
    @Length(max = 255, message = "组织名不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String name;

    /** 组织代码 */
    @NotBlank(message = "组织代码不能为空")
    @Length(max = 255, message = "组织代码不能超过{max}位")
    @Column(length = 255, nullable = false, unique = true)
    private String code;

    /**
     * 关联用户
     */
    @ManyToMany(mappedBy = "oganizations")
    private List<AuthUser> users = new ArrayList<>();

    @ManyToOne
    private AuthOganization parent;

}
